<template>
    <Form ref="form" :model="model" :rules="rules" @validate="errors=$event" :messages="messages">
        <div class="e-form-input">
            <Label for="username" align="left">用户名:</Label>
            <TextBox inputId="username" name="username" v-model="model.username" style="width: 300px"
                     v-Tooltip="getTipOpts('username')"></TextBox>
        </div>
        <div class="e-form-input">
            <Label for="phone" align="left">手机号:</Label>
            <TextBox inputId="phone" name="phone" v-model="model.phone" style="width: 300px"
                     v-Tooltip="getTipOpts('phone')"></TextBox>
        </div>
        <div class="e-form-input">
            <Label for="password" align="left">密码:</Label>
            <TextBox inputId="password" name="password" v-model="model.password" style="width: 300px"
                     v-Tooltip="getTipOpts('password')"></TextBox>
        </div>
        <div style="margin: 10px;text-align: right;">
            <LinkButton @click="submitForm()" iconCls="icon-save">保存</LinkButton>
        </div>
    </Form>
</template>

<script>
    import {mixinForm} from "@/common/form.mixin";

    export default {
        name: "eForm",
        mixins: [mixinForm],
        props: {
        },
        data() {
            return {
                rules: {
                    username: ["required", "length[2,12]"],
                    phone: ["required", "length[2,12]"],
                    password: ["required", "length[6,12]"],
                },
                messages: {
                    username: {
                        required: "用户名必填"
                    },
                    phone: {
                        required: "手机号必填"
                    },
                    password: {
                        required: "密码必填"
                    }
                }
            };
        },
        methods: {
            add(request) {
                this.$e.api.adminAdd(request.object).then(res => {
                    let [, code, message] = res
                    if (code === 200) {
                        this.$emit('addEnd')
                    }
                })
            },
            update(request) {

            }
        }
    };
</script>